<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0"><meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />  
        <title>Welcome to Design Zone......</title>
        <link rel="stylesheet" type="text/css" href="../../scripts/ext/resources/css/ext-all.css" />
        <link rel="stylesheet" type="text/css" href="../../styles/dzbase.css" />
        <script type="text/javascript" src="../../scripts/ext/adapter/ext-base.js">
        </script>
        <script type="text/javascript" src="../../scripts/ext/ext-all.js">
        </script>
		
		<script type="text/javascript" src="../../scripts/menu/EditableItem.js"></script>
		<script type="text/javascript" src="../../scripts/menu/RangeMenu.js"></script>
		<script type="text/javascript" src="../../scripts/grid/GridFilters.js"></script>
		<script type="text/javascript" src="../../scripts/grid/filter/Filter.js"></script>
		<script type="text/javascript" src="../../scripts/grid/filter/StringFilter.js"></script>
		
        <script type="text/javascript" src="../../scripts/i18nMessage.js">
        </script>
        <script type="text/javascript" src="../../scripts/utils.js">
        </script>
		
        <script type="text/javascript">
        	var fcMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.francecustomer');
			var message = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=message');
        	var store;
            var grid;
            
            var deleteCallback = function(btn){
                if (btn == 'yes') {
                    Ext.Ajax.request({
                        url: '../../servlet/BiFranceCustomerServlet?action=2&id=' + deleteId,
                        success: function(o){
                            if (o.responseText == 'success') {
                                store.reload();
                                messageTip.msg(message.get('message.tip'), message.get('message.delete.successful'));
                            }
                            else {
                                messageTip.msg(message.get('message.tip'), message.get('message.delete.unsuccessful'));
                            }
                        },
                        failure: function(o){
                            messageTip.msg(message.get('message.tip'), message.get('message.delete.failure'));
                        },
                        params: {
                            foo: 'bar'
                        }
                    });
                }
            }
			
			 Ext.onReady(function(){
                
                store = new Ext.data.Store({
                    url: '../../servlet/BiFranceCustomerServlet?action=4',
                    
                    reader: new Ext.data.XmlReader({
                        record: 'item',
                        id: 'id',
                        totalRecords: 'itemTotal'
                    }, [ 
                    'index', 'name', 'department', 
					 'contactRehearsals',
					 'rehearsalsPhone',
					 'rehearsalsEmail',
					 'rehearsalsFax',
					 'rehearsalsMobile',	
					 
					 'contactPurchases',
					 'purchasesPhone',
					 'purchasesEmail',
					 'purchasesFax',
					 'purchasesMobile',	
					 
					 'contactSupplies', 
					 'suppliesPhone',
					 'suppliesEmail',
					 'suppliesFax',
					 'suppliesMobile',
					 
					 'contactLogistics', 
					 'logisticsPhone',
					 'logisticsEmail',
					 'logisticsFax',
					 'logisticsMobile',
					 
					 'contactQuality', 
					 'qualityPhone',
					 'qualityEmail',
					 'qualityFax',
					 'qualityMobile',
					 
					 'contactInvoice',
					 'invoicePhone',
					 'invoiceEmail',
					 'invoiceFax',
					 'invoiceMobile',
					 
					 'addressBill',
					 //'addressDelivery',
					 'addressRehearsals',
					 'addressProduct',
					 
					 'isPrDiscount',
					 'prDiscount',
					 'isProductionAdvancePayment',
					 'productionAdvancePayment',
					 'isProductionGoodsDeparture',
					 'productionGoodsDeparture',
					 'isProductionLcPayment',
					 'productionLcPayment',
					 'isProductionDiscount',
					 'productionDiscount',
					 
					 'remark','id']),
                    
                    remoteSort: true
                });
                
                store.setDefaultSort('id', 'desc');
				
				var filters = new Ext.grid.GridFilters({
					  filters:[
					    {type: 'string',  dataIndex: 'name'},
					    {type: 'string',  dataIndex: 'department'}
					]});
                
                // create the grid
                grid = new Ext.grid.GridPanel({
                    title: fcMessage.get('ui.francecustomer.listtitle'),
                    store: store,
					stripeRows: true,
					plugins: filters,
                    height: 560,
                    columns: [{
                        header: message.get('message.list.id'),
                        width: 20,
                        dataIndex: 'index',
                        sortable: false
                    }, {
                        header: fcMessage.get('ui.francecustomer.name'),
                        width: 80,
                        dataIndex: 'name',
                        sortable: true
                    }, {
                        header: fcMessage.get('ui.francecustomer.department'),
                        dataIndex: 'department',
                        sortable: true
                    },{
                        header: fcMessage.get('ui.francecustomer.memo'),
                        width: 20,
                        dataIndex: 'id',
                        sortable: false,
                        renderer: renderMemo
                    },{
                        header: message.get('message.list.eidt'),
                        width: 20,
                        dataIndex: 'id',
                        sortable: false,
                        renderer: renderEdit
                    },{
                        header: message.get('message.list.delete'),
                        width: 20,
                        dataIndex: 'id',
                        sortable: false,
                        renderer: renderDelete
                    }],
                    viewConfig: {
                        forceFit: true
                    },
                    loadMask: true,
                    renderTo: 'biFranceCustomer',
                    bbar: new Ext.PagingToolbar({
                        pageSize: 20,
                        store: store,
                        displayInfo: true
                    })
                });
                
                var startPage = getPrarmeterValue(window.location, 'startPage');
                var start;
                if (startPage == null || startPage == '') {
                    start = 0;
                }
                else {
                    start = (startPage - 1) * 20;
                }
                store.load({
                    params: {
                        start: start,
                        limit: 20
                    }
                });
				
				function renderMemo(value, p, record){
                    return String.format('<a href="france_customer_visit_memo_edit.html?id={0}&startPage={1}" target="_self"><img src="../../images/icons/comments.png" title="' + fcMessage.get('ui.francecustomer.memo') + '" /></a>', record.id, Math.floor((record.data.index - 1) / 20) + 1);
                }
                
                function renderEdit(value, p, record){
                    return String.format('<a href="france_customer_edit.html?id={0}&startPage={1}" target="_self"><img src="../../images/icons/pencil.png" title="' + message.get('message.list.eidt') + '" /></a>', record.id, Math.floor((record.data.index - 1) / 20) + 1);
                }
                
                function renderDelete(value, p, record){
                    return String.format('<a href="javascript: deleteItem(deleteCallback, {0});"><img src="../../images/icons/delete.png" title="' + message.get('message.list.delete') + '"/></a>', record.id);
                }
                
                var detailWin;
                grid.on('rowdblclick', function(grid, rowIndex, e){
                    if (!detailWin) {
                        detailWin = new Ext.Window({
                            title: message.get('message.window.detail'),
                            layout: 'fit',
                            width: 800,
                            height: 480,
                            closeAction: 'hide',
                            plain: true,
                            items: [{
                                id: 'detailPanel',
                                region: 'center',
                                bodyStyle: {
                                    background: '#ffffff',
                                    padding: '7px'
                                },
                                html: message.get('message.window.empty')
                            }]
                        });
                    }
                    
                    detailWin.show(this);
                    var itemTplMarkup = [
						'<table cellspacing="0" id="the-table"><tbody>',
							'<tr><td style="background:#eeeeee;">',
							message.get('message.list.id'),
							'</td><td>{id}</td>',
							'<td style="background:#eeeeee;">',
							fcMessage.get('ui.francecustomer.name'),
							'</td><td>{name}</td>',
							'<td style="background:#eeeeee;">',
							fcMessage.get('ui.francecustomer.department'),
							'</td><td colspan="5">{department}</td></tr>',
							
							'<tr><td style="background:#eeeeee;">',
							fcMessage.get('ui.francecustomer.contactrehearsals'),
							'</td><td>{contactRehearsals}</td>',
							'<td style="background:#eeeeee;">',
							message.get('message.edit.phone'),
							'</td><td>{rehearsalsPhone}</td>',
							'<td style="background:#eeeeee;">',
							message.get('message.edit.email'),
							'</td><td>{rehearsalsEmail}</td>',
							'<td style="background:#eeeeee;">',
							message.get('message.edit.fax'),
							'</td><td>{rehearsalsFax}</td>',
							'<td style="background:#eeeeee;">',
							message.get('message.edit.mobile'),
							'</td><td>{rehearsalsMobile}</td></tr>',
							
							'<tr><td style="background:#eeeeee;">',
							fcMessage.get('ui.francecustomer.contactpurchases'),
							'</td><td>{contactPurchases}</td>',
							'<td style="background:#eeeeee;">',
							message.get('message.edit.phone'),
							'</td><td>{purchasesPhone}</td>',
							'<td style="background:#eeeeee;">',
							message.get('message.edit.email'),
							'</td><td>{purchasesEmail}</td>',
							'<td style="background:#eeeeee;">',
							message.get('message.edit.fax'),
							'</td><td>{purchasesFax}</td>',
							'<td style="background:#eeeeee;">',
							message.get('message.edit.mobile'),
							'</td><td>{purchasesMobile}</td></tr>',
							
							'<tr><td style="background:#eeeeee;">',
							fcMessage.get('ui.francecustomer.contactsupplies'),
							'</td><td>{contactSupplies}</td>',
							'<td style="background:#eeeeee;">',
							message.get('message.edit.phone'),
							'</td><td>{suppliesPhone}</td>',
							'<td style="background:#eeeeee;">',
							message.get('message.edit.email'),
							'</td><td>{suppliesEmail}</td>',
							'<td style="background:#eeeeee;">',
							message.get('message.edit.fax'),
							'</td><td>{suppliesFax}</td>',
							'<td style="background:#eeeeee;">',
							message.get('message.edit.mobile'),
							'</td><td>{suppliesMobile}</td></tr>',
							
							'<tr><td style="background:#eeeeee;">',
							fcMessage.get('ui.francecustomer.contactlogistics'),
							'</td><td>{contactLogistics}</td>',
							'<td style="background:#eeeeee;">',
							message.get('message.edit.phone'),
							'</td><td>{logisticsPhone}</td>',
							'<td style="background:#eeeeee;">',
							message.get('message.edit.email'),
							'</td><td>{logisticsEmail}</td>',
							'<td style="background:#eeeeee;">',
							message.get('message.edit.fax'),
							'</td><td>{logisticsFax}</td>',
							'<td style="background:#eeeeee;">',
							message.get('message.edit.mobile'),
							'</td><td>{logisticsMobile}</td></tr>',
							
							'<tr><td style="background:#eeeeee;">',
							fcMessage.get('ui.francecustomer.contactquality'),
							'</td><td>{contactQuality}</td>',
							'<td style="background:#eeeeee;">',
							message.get('message.edit.phone'),
							'</td><td>{qualityPhone}</td>',
							'<td style="background:#eeeeee;">',
							message.get('message.edit.email'),
							'</td><td>{qualityEmail}</td>',
							'<td style="background:#eeeeee;">',
							message.get('message.edit.fax'),
							'</td><td>{qualityFax}</td>',
							'<td style="background:#eeeeee;">',
							message.get('message.edit.mobile'),
							'</td><td>{qualityMobile}</td></tr>',
							
							'<tr><td style="background:#eeeeee;">',
							fcMessage.get('ui.francecustomer.contactfinance'),
							'</td><td>{contactInvoice}</td>',
							'<td style="background:#eeeeee;">',
							message.get('message.edit.phone'),
							'</td><td>{invoicePhone}</td>',
							'<td style="background:#eeeeee;">',
							message.get('message.edit.email'),
							'</td><td>{invoiceEmail}</td>',
							'<td style="background:#eeeeee;">',
							message.get('message.edit.fax'),
							'</td><td>{invoiceFax}</td>',
							'<td style="background:#eeeeee;">',
							message.get('message.edit.mobile'),
							'</td><td>{invoiceMobile}</td></tr>',
							
							'<tr><td style="background:#eeeeee;">',
							fcMessage.get('ui.francecustomer.addressbill'),
							'</td><td colspan="9">{addressBill}</td></tr>',
							//'<tr><td style="background:#eeeeee;">',
							//fcMessage.get('ui.francecustomer.addressdelivery'),
							//'</td><td colspan="9">{addressDelivery}</td></tr>',
							'<tr><td style="background:#eeeeee;">',
							fcMessage.get('ui.francecustomer.addressrehearsals'),
							'</td><td colspan="9">{addressRehearsals}</td></tr>',
							'<tr><td style="background:#eeeeee;">',
							fcMessage.get('ui.francecustomer.addressproduct'),
							'</td><td colspan="9">{addressProduct}</td></tr>',
							
							
							'<tr><td colspan="10" style="background:#eeeeee;">',
							fcMessage.get('ui.francecustomer.er') + '&nbsp;&nbsp;&nbsp;&nbsp;' + fcMessage.get('ui.francecustomer.cashtt'),
							'</td></tr>',
							
							'<tr><td style="background:#eeeeee;">',
							fcMessage.get('ui.francecustomer.discount'),
							'</td><td>' + renderYesno(grid.getStore().getAt(rowIndex).data.isPrDiscount) + '</td>',
							'<td colspan="9">',
							'{prDiscount}%',
							'</td></tr>',
							
							'<tr><td colspan="10" style="background:#eeeeee;">',
							fcMessage.get('ui.francecustomer.product'),
							'</td></tr>',
							
							'<tr><td style="background:#eeeeee;">',
							fcMessage.get('ui.francecustomer.advancepayment'),
							'</td><td>' + renderYesno(grid.getStore().getAt(rowIndex).data.isProductionAdvancePayment) + '</td>',
							'<td colspan="3">{productionAdvancePayment}%</td>',
							'<td style="background:#eeeeee;">',
							fcMessage.get('ui.francecustomer.goodspayment'),
							'</td><td>' + renderYesno(grid.getStore().getAt(rowIndex).data.isProductionGoodsDeparture) + '</td>',
							'<td colspan="3">{productionGoodsDeparture}%</td></tr>',
							
							'<tr><td style="background:#eeeeee;">',
							fcMessage.get('ui.francecustomer.paymentlc'),
							'</td><td>' + renderYesno(grid.getStore().getAt(rowIndex).data.isProductionLcPayment) + '</td>',
							'<td colspan="3">{productionLcPayment}%</td>',
							'<td style="background:#eeeeee;">',
							fcMessage.get('ui.francecustomer.discount'),
							'</td><td>'+ renderYesno(grid.getStore().getAt(rowIndex).data.isProductionDiscount) + '</td>',
							'<td colspan="3">{productionDiscount}%</td></tr>',
							
						'</tbody></table>'
					
					
					];
                    var itemTpl = new Ext.Template(itemTplMarkup);
                    var detailPanel = Ext.getCmp('detailPanel');
                    itemTpl.overwrite(detailPanel.body, grid.getStore().getAt(rowIndex).data);
                });
                
                
            });
                    
             function renderYesno(value, p, record){
                if(value == '01'){
					return String.format('<img ext:qtip="{0}" src="../../images/icons/tick.png" /></a>', message.get('message.list.yes'));		
				}else{
					return String.format('<img ext:qtip="{0}" src="../../images/icons/cross.png" /></a>', message.get('message.list.no'));				
				}
            }       
        </script>
    </head>
    <body>
        <div id="biFranceCustomer">
        </div>
    </body>
</html>
